﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using GMS.Dinasty.BO;
using GMS.Dinasty.DAL;
using GMS.BasicControls;
using GMS.MainClasses;
using System.Collections;

namespace GMS.BasicControls
{
    public partial class UsersList : BackGroundControl
    {
        public UsersList()
        {
            InitializeComponent();
        }
        private List<User> _curUsers;
        public List<User> CurUsers
        {
            get
            {
                return _curUsers;
            }
            set
            {
                _curUsers = value;
            }
        }
        private List<User> _allUsers;
        public List<User> AllUsers
        {
            get { return _allUsers; }
            set { _allUsers = value; }
        }
        private void UsersList_Load(object sender, EventArgs e)
        {

            _allUsers.Sort();

            foreach (User user in _allUsers)
            {
                int f = _curUsers.BinarySearch(user);
                if (f >= 0)
                {
                    checkedListBox1.Items.Add(user, CheckState.Checked);
                }
                else
                {
                    checkedListBox1.Items.Add(user, CheckState.Unchecked);
                }
            }
        }

        private void closeLabel_MouseDown(object sender, MouseEventArgs e)
        {
            _curUsers.Clear();
            foreach (User user in checkedListBox1.Items)
            {
                if (checkedListBox1.GetItemChecked(checkedListBox1.Items.IndexOf(user)))
                {
                    _curUsers.Add(user);
                }
            }
        }

    }
}
